package com.prdiot.poetry.service;

import com.prdiot.poetry.dao.ChengyuRepository;
import com.prdiot.poetry.dao.PoemsRepository;
import com.prdiot.poetry.domains.Chengyu;
import com.prdiot.poetry.domains.Mingju;
import com.prdiot.poetry.domains.Poems;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Service
public class ChengyuService {

    @Autowired
    ChengyuRepository chengyuRepository;

    //随机获取Chengyu
    public List<Chengyu> getRandPoetry() {
        return chengyuRepository.getRandChengyu();
    }

    public Page<Chengyu> getChengyuList(Pageable pageable){
        return  chengyuRepository.getChengyuList(pageable);
    }

    public Chengyu findByCode(String code){
        Optional<Chengyu> chengyuOptional = chengyuRepository.findByCode(code);
        if (chengyuOptional.isPresent()){
            return  chengyuOptional.get();
        }
        return null;
    }

}
